#ifndef GML__ALGO_BASE_H
#define GML__ALGO_BASE_H

#include "config.h"

#define copy(_Dst, _Src, _dstFirst, _srcFirst, _srcLast) ({ \
    defineArg(_dstFirst, __dstFirst); \
    defineArg(_srcFirst, __srcFirst); \
    defineArg(_srcLast, __srcLast); \
    for (; _Src##IteratorNotEqualTo(&__srcFirst, &__srcLast); _Src##IteratorIncreasePrefix(&__srcFirst)) { \
        *_Dst##IteratorIndirect(&__dstFirst) = *_Src##IteratorIndirect(&__srcFirst); \
        _Dst##IteratorIncreasePrefix(&__dstFirst); \
    } \
    __dstFirst; \
})

#define copyBackward(_Dst, _Src, _dstLast, _srcFirst, _srcLast) ({ \
    defineArg(_dstLast, __dstLast); \
    defineArg(_srcFirst, __srcFirst); \
    defineArg(_srcLast, __srcLast); \
    while (_Src##IteratorNotEqualTo(&__srcFirst, &__srcLast)) { \
        *_Dst##IteratorIndirect(_Dst##IteratorDecreasePrefix(&__dstLast)) = *_Src##IteratorIndirect(_Src##IteratorDecreasePrefix(&__srcLast)); \
    } \
    __dstLast; \
})

#endif // GML__ALGO_BASE_H
